package com.shujia.mvc3.service;

import com.shujia.mvc3.dao.UserDao;
import com.shujia.mvc3.dao.UserMysqlDaoImpl;
import com.shujia.mvc3.dao.UserOracleDaoImpl;
import com.shujia.mysql.User;

public class UserServiceImpl {
    static UserDao userDao=new UserOracleDaoImpl();
    public static String verification(String username,String password){
        User user = userDao.login(username);
        if(user.getUsername()==null){
//            System.out.println("用户名不存在");
            return "用户名不存在";
        }
        if(!user.getPassword().equals(password)){
//            System.out.println("密码不正确");
            return "密码不正确";
        }
        return "登录成功";
    }
    public static String  register(String username,String password,String newPassword){
        if (username.length()<5 || username.length()>12){//>=5<=12
//            System.out.println("用户名账户长度不是>=5<=12");
            return "用户名账户长度不是>=5<=12";
        }
        if(password.length()<5||password.length()>15){
//            System.out.println("密码长度不是>=5<=12");
            return "密码长度不是>=5<=12";
        }
        if (!password.equals(newPassword)){
//            System.out.println("密码不一样");
            return "密码不一样";
        }
        User user = userDao.login(username);
        if(user.getUsername()!=null){
//            System.out.println("不能注册 用户已存在");
            return "不能注册 用户已存在";
        }

        int insert = userDao.register(username, password);
        return "注册成功";

    }
}
